package operation;

import book.List.bookList;
import book.List.book ;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:岁亮亮
 * Date:2024-01-08
 * TIME:20:58
 */
public class borrowed implements IOoperation {

    @Override
    public void work(bookList bookList) {
        System.out.println("借阅图书");
        System.out.println("请输入你要借的图书");
        Scanner scanner=new Scanner(System.in);
        String str=scanner.nextLine();
        int endnumer=bookList .getUsesize();
        int pos=-1;
        for (int i = 0; i < endnumer; i++) {
            book book=bookList.getBook(i);
            if(book.getName().equals(str)){
                pos=i;break;
            }
        }
        book book=bookList.getBook(pos);
        if(pos==-1){
            System.out.println("没有找到你要借的图书");
        }
        else if(book.isIsborrow()){
            System.out.println("你要借的书已被借出请下次再借");
        }
        else {
            book.setIsborrow(true) ;
            System.out.println("借阅成功");
        }
    }
}
